﻿namespace Sidvall.CodeGenerator
{
	public class DomainObjectIndexCollection : System.Collections.ObjectModel.KeyedCollection<string, DomainObjectIndex>
	{
		#region Business Members

		#region GetKeyForItem

		protected override string GetKeyForItem(DomainObjectIndex item)
		{
			if (item == null)
				throw new System.ArgumentNullException("item");

			return DomainObjectIndex.GetKey(item);
		}

		#endregion
		#region Import

		public void Import(System.Collections.Generic.IEnumerable<DomainObjectIndex> items)
		{
			string key;

			if (items == null)
				return;

			foreach (var item in items)
			{
				key = DomainObjectIndex.GetKey(item);
				if (Contains(key))
					this[key].Import(item);
				else
					Add(item);
			}
		}

		#endregion

		#endregion
		#region Constructors

		public DomainObjectIndexCollection()
			: base(System.StringComparer.OrdinalIgnoreCase)
		{
		}

		#endregion
	}
}
